<template>
	<view>
		<u-navbar title="搜索" :autoBack="true" :bgColor="them_color" :titleStyle="{color:'#ffffff'}"
			leftIconColor="#ffffff">
		</u-navbar>
		<view class='searchGood' :style="'margin-top:' + navH + 'px;'">
			<view class='search acea-row row-between-wrapper'>
				<view class='input acea-row row-between-wrapper'>
					<text class='iconfont icon-sousuo'></text>
					<input type='text' v-model='searchValue' @confirm="inputConfirm" focus placeholder='搜索名称'
						placeholder-class='placeholder' @input="setValue"></input>
				</view>
				<view class='bnt' @tap='searchBtn'>搜索</view>
			</view>
			<view class='line' v-if='bastList.length'></view>
			<view class='title'>热门搜索</view>
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback">
				<view class="goodList">
					<view @click="goDetail(item)" class='item acea-row row-between-wrapper' hover-class="none"
						v-for="(item,index) in bastList" :key="index">
						<view class='pictrue'>
							<image :src='item.goods_thumb' mode="aspectFit"></image>
						</view>
						<view class='underline'>
							<view class='text'>
								<view class='line1'>{{item.goods_name}}</view>
								<view class='money font-color'>￥<text class='num'>{{item.shop_price}}</text></view>
								<view class='vip-money acea-row row-middle'
									v-if="item.vip_price && item.vip_price > 0 && item.shop_price != '面议'">VIP
									￥{{item.vip_price || 0}}
									<!-- <image src='@/static/images/vip.png'></image><text
									class='num'>已售 {{item.sales}}{{item.unit_list.unit_name}}</text> -->
								</view>
								<view class='vip-money acea-row row-middle' v-else>
									<!-- <text class='num'>已售 {{item.sales}}{{item.unit_list.unit_name}}</text> -->
								</view>
							</view>
						</view>
					</view>
				</view>
			</mescroll-body>
		</view>
		<view class='noCommodity'>
			<view class='pictrue' v-if="bastList.length == 0">
				<u-empty mode="search" icon="http://cdn.uviewui.com/uview/empty/search.png"></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import {
		mapGetters
	} from "vuex";
	import {
		search_goods
	} from '@/api/store.js';
	export default {
		mixins: [MescrollMixin],
		computed: mapGetters(["area_id"]),
		data() {
			return {
				navH: '',
				them_color: getApp().globalData.theme_color,
				searchValue: '',
				focus: true,
				bastList: [],
			};
		},
		onLoad(e) {
			uni.showLoading({
				title: '加载中...'
			})
			this.navH = getApp().globalData.navHeight / 2 + 10;
		},
		methods: {
			upCallback(page) {
				var that = this;
				search_goods({
					cat_id: '',
					supplier_id: getApp().globalData.supplier_id,
					goods_name: that.searchValue,
					order: '',
					sort: '',
					page: 1,
					brand_id: '',
					is_sbest: 0, //精 品 0否1是
					is_shot: 0, //热卖 0否1是
					is_snew: 0, //新品 0否1是
					area: '',
					lng: '',
					lat: '',
					goods_nature: 0 //1普通商品 2 景点
				}).then(async (res) => {
					uni.hideLoading()
					this.mescroll.endSuccess(res.data.length);

					//设置列表数据
					if (page.num == 1) this.bastList = []; //如果是第一页需手动制空列表
					this.bastList = this.bastList.concat(res.data); //追加新数据

				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			inputConfirm: function(event) {
				if (event.detail.value) {
					uni.hideKeyboard();
					this.setHotSearchValue(event.detail.value);
				}
			},
			setHotSearchValue: function(event) {
				this.$set(this, 'searchValue', event);
				// this.$set(this, 'bastList', []);
				this.searchBtn()
			},
			setValue: function(event) {
				this.$set(this, 'searchValue', event.detail.value);
			},
			searchBtn: function() {
				let that = this;
				// if (!that.searchValue.trim()) return this.$util.Tips({
				// 	title: '请输入要搜索的商品'
				// });
				that.focus = false;
				uni.showLoading({
					title: '搜索中...'
				})
				that.mescroll.resetUpScroll()
			},
			goDetail(item) {
				uni.navigateTo({
					url: `/pages/goods/detail/index?goods_id=${item.goods_id}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #fff !important;
	}

	.noCommodity {
		border-top-width: 0;
	}

	.searchGood .search {
		padding-left: 30rpx;
	}

	.searchGood .search {
		margin-top: 20rpx;
	}

	.searchGood .search .input {
		width: 598rpx;
		background-color: #f7f7f7;
		border-radius: 33rpx;
		padding: 0 35rpx;
		box-sizing: border-box;
		height: 66rpx;
		border: 1px solid rgba(212, 212, 212, 1.0);
	}

	.searchGood .search .input input {
		width: 472rpx;
		font-size: 28rpx;
	}

	.searchGood .search .input .placeholder {
		color: #999;
	}

	.searchGood .search .input .iconfont {
		color: #555;
		font-size: 35rpx;
	}

	.searchGood .search .bnt {
		width: 120rpx;
		text-align: center;
		height: 66rpx;
		line-height: 66rpx;
		font-size: 30rpx;
		color: #282828;
	}

	.searchGood .title {
		font-size: 28rpx;
		color: #999;
		margin: 50rpx 30rpx 25rpx 30rpx;
	}

	.searchGood .title .iconfont {
		font-size: 28rpx;
	}

	.searchGood .list {
		padding-left: 10rpx;
	}

	.searchGood .list .item {
		font-size: 26rpx;
		color: #454545;
		padding: 0 21rpx;
		height: 60rpx;
		border-radius: 3rpx;
		line-height: 60rpx;
		border: 1rpx solid #aaa;
		margin: 0 0 20rpx 20rpx;
	}

	.searchGood .list .item.history-item {
		height: 50rpx;
		border: none;
		border-radius: 25rpx;
		background-color: #F7F7F7;
		line-height: 50rpx;
	}

	.searchGood .line {
		border-bottom: 1rpx solid #eee;
		margin: 20rpx 30rpx 0 30rpx;
	}

	.goodList .item {
		position: relative;
		padding-left: 30rpx;
	}

	.goodList .item .pictrue {
		width: 180rpx;
		height: 180rpx;
		position: relative;
	}

	.goodList .item .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 20rpx;
	}

	.goodList .item .pictrue .numPic {
		position: absolute;
		left: 7rpx;
		top: 7rpx;
		width: 40rpx;
		height: 40rpx;
		border-radius: 50%;
	}

	.goodList .item .underline {
		padding: 30rpx 30rpx 30rpx 0;
		border-bottom: 1px solid #f5f5f5;
	}

	.goodList .item:nth-last-child(1) .underline {
		border-bottom: 0;
	}

	.goodList .item .text {
		font-size: 30rpx;
		color: #222;
		width: 489rpx;
	}

	.goodList .item .text .money {
		font-size: 26rpx;
		font-weight: bold;
		margin-top: 50rpx;
	}

	.goodList .item .text .money .num {
		font-size: 34rpx;
	}

	.goodList .item .text .vip-money {
		font-size: 24rpx;
		color: #282828;
		font-weight: bold;
		margin-top: 15rpx;
	}

	.goodList .item .text .vip-money image {
		width: 66rpx;
		height: 25rpx;
		margin-right: 8rpx;
		margin-left: 8rpx;
	}

	.goodList .item .text .vip-money .num {
		font-size: 22rpx;
		color: #aaa;
		font-weight: normal;
		margin-top: -2rpx;

		~.num {
			margin-left: 22rpx;
		}
	}

	.goodList .item .iconfont {
		position: absolute;
		right: 30rpx;
		width: 50rpx;
		height: 50rpx;
		border-radius: 50%;
		font-size: 30rpx;
		bottom: 38rpx;
	}
</style>